﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Portal.Logic;
using Portal.Common.Entity;
using OC.Common.Entity;
using Portal.Common.Interface;
using Common.Service;

namespace Portal.AjaxPage
{
    public partial class PersonSettingPage : System.Web.UI.Page
    {
        private IDectionary _IDectionary;
        public IDectionary IDectionary 
        {
            get 
            {
                if (_IDectionary == null) 
                {
                    _IDectionary = ServiceContainer.GetService<IDectionary>();
                }
                return _IDectionary;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) 
            {
                int count = GetData();
                Response.Write(count);
                Response.End();
            }
        }

        public int GetData() 
        {
            int count = 0;
            int num = string.IsNullOrEmpty(Request["num"].ToString()) == true ? 0 : Convert.ToInt32(Request["num"].ToString());
            string item = string.IsNullOrEmpty(Request["item"]) == true ? "" : Request["item"].ToString();
            string value = string.IsNullOrEmpty(Request["value"]) == true ? "" : Request["value"].ToString();
            List<DectionaryEntity> ent = IDectionary.GetById(value);
            if (num>0) 
            {
                if (num % 2 == 0)
                {
                    UserEntity user = Session["UserInfo"]as UserEntity;
                    //插入数据
                    PersonSettingEntity entity = new PersonSettingEntity();
                    entity.SETTING_VALUE = ent[0].EXT02;
                    entity.SETTING_ITEMS = item.Trim();
                    entity.SETTING_TYPE = "4";
                    entity.UPDATE_BY = user.CN_NAME;
                    entity.UPDATE_DATE = DateTime.Now;
                    entity.USER_ID = user.USER_ID;
                    entity.IS_ACTIVE = "0";
                    entity.DELEGATOR_STATUS = "0";
                    entity.CREATE_BY = user.CN_NAME;
                    entity.CREATE_DATE = DateTime.Now;
                    entity.EFFECT_FROM = DateTime.Now;
                    new PersonSettingLogic().InserData(entity);
                }
                else 
                {
                    //删除数据
                    PersonSettingLogic logic = new PersonSettingLogic();
                    count = logic.DeleteByParams(item, value);
                }
            }
            return count;
        } 
    }
}